package com.itheima.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;
@Component
public class YunSmsUtils {

    @Autowired
    private  RestTemplate restTemplate;

    public  boolean sendYunzhixunMsg(String mobile, Integer code, Integer time){
        Map<String,String> param = new HashMap<>();
        param.put("sid","0c71daeb7f24a6ef768cb00b132c5624");
        param.put("token","38c5b2f652edec2cd5d7d26e58ab510e");
        param.put("appid","70cabdc8fa3349429417d0580bcead2f");
        param.put("templateid","564697");
        param.put("param",code+","+time);
        param.put("mobile",mobile);
        ResponseEntity<Map> responseEntity = restTemplate.postForEntity("https://open.ucpaas.com/ol/sms/sendsms", param, Map.class);

        if (responseEntity.getStatusCode().is2xxSuccessful()){
            Map body = responseEntity.getBody();
            if ("000000".equals(body.get("code"))){
                return true;
            }
        }
        return false;
    }



}
